var e = require("../../api.js"), rr = require("../../utils.js"), o = getApp();

Page({
    data: {
        order: null,
        getGoodsTotalPrice: function() {
            return this.data.order.total_price;
        },
        showGoods: 0,
        refund_pic: ''
    },
    onLoad: function(t) {
        o.pageOnLoad(this, t);
        var r = this, n = "";
        if ("undefined" == typeof my) n = t.scene; else if (null !== o.query) {
            var c = o.query;
            o.query = null, n = c.order_no;
        }
        r.setData({
            store: wx.getStorageSync("store"),
            user_info: wx.getStorageSync("user_info")
        }), wx.showLoading({
            title: "正在加载"
        }), o.request({
            url: e.order.shop_refund,
            data: {
                order_no: n
            },
            success: function(e) {
                0 == e.code ? r.setData({
                    order: e.data
                }) : wx.showModal({
                    title: "警告！",
                    showCancel: !1,
                    content: e.msg,
                    confirmText: "确认",
                    success: function(e) {
                        e.confirm && wx.switchTab({
                            url: "/pages/index/index"
                        });
                    }
                });
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    showGoodsBtn() {
      var that = this;
      that.setData({
        showGoods: !that.data.showGoods
      })
    },
    chooseImage: function(t) {
        var e = this
        wx.chooseImage({
            count: 1,
            success: function(t) {
                wx.showLoading({
                    title: "正在加载"
                })
                wx.uploadFile({
                    url: getApp().api.default.upload_image,
                    name: "image",
                    formData: {},
                    filePath: t.tempFilePaths[0],
                    complete: function (res) {
                        wx.hideLoading();
                        res = JSON.parse(res.data)
                        if (res.code == 0) {
                            e.setData({
                                refund_pic: res.data.url
                            })
                        }else {
                            wx.showModal({
                              title: '提示',
                              content: res.msg,
                              showCancel: !1,
                            })
                        }
                    }
                }); 
            }
        });
    
    },
    saveSubmit:function (t) {
        var that = this;
        if (!t.detail.value.refund_price > 0) {
            wx.showModal({
                title: "提示！",
                showCancel: !1,
                content: '请填写理赔金额',
                confirmText: "确认",
            })
            return false;
        }
        if (t.detail.value.refund_price > that.data.order.refund_price) {
            wx.showModal({
                title: "提示！",
                showCancel: !1,
                content: '理赔金额不能超过' + that.data.order.refund_price,
                confirmText: "确认",
            })
            return false;
        }
        wx.showLoading({
            title: "正在加载"
        })
        o.request({
            url: e.order.save_shop_refund,
            data: {
                order_no: that.data.order.order_no,
                refund_price: t.detail.value.refund_price,
                desc: t.detail.value.desc,
                pic_url: that.data.refund_pic
            },
            success: function(e) {
                0 < e.code ?wx.showModal({
                title: "提示！",
                showCancel: !1,
                content: e.msg,
                confirmText: "确认",
                }) : wx.showModal({
                    title: "提示！",
                    showCancel: !1,
                    content: e.msg,
                    confirmText: "确认",
                    success: function(e) {
                        e.confirm && wx.switchTab({
                            url: "/pages/index/index"
                        });
                    }
                });
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    }
});